package 其他.求第K小的字符的索引;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        int k = scanner.nextInt();
        ArrayList<Character> list = new ArrayList<Character>();
        for (int i = 0; i < s.length(); i++) {
            list.add(s.charAt(i));
        }
        Collections.sort(list);
        char min = 0;
        int num = 1;
        for (Character character : list) {
            // K 大于这个 字符串的长度 那么输出最大的那一个字符的索引
            if (k > s.length()) {
                if (num == list.size()) {
                    min = character; // 最后一个字符
                }
            }
            if (num == k) {
                min = character;
                break;
            }
            num++;
        }

        for (int i = 0; i < s.length(); i++) {
            if (min == s.charAt(i)) {
                System.out.println(i);
                break;
            }
        }

    }
}
